#!/bin/bash

# 该脚本需要root用户下执行,安装rrd

BUILD_DIR=/data/rrdbuild
INSTALL_DIR=/data/rrdtool


# 下载解压
down () {
    wget http://oss.oetiker.ch/rrdtool/pub/rrdtool-1.4.3.tar.gz
    gunzip -c rrdtool-1.4.3.tar.gz | tar xf -
}

# 安装
install () {
    ./configure --prefix=$INSTALL_DIR && make && make install
}

# 测试安装成功与否
test_version () {
    version=$(/usr/local/rrdtool/bin/rrdtool -v)
    echo $version
}

# 不成功则采取以下措施,并再次安装
solve () {
    apt-get install libcairo2-dev libglib2.0-dev libpango1.0-dev -y**
    apt install cairo-* libxml2-dev pango1.0-tests -y**
}

mkdir -p $BUILD_DIR
cd $BUILD_DIR
down
cd rrdtool-1.4.3
install
useage=test_version
while [ ! -n $useage ]; do
    solve
done
echo $useage
# 创建软连接
ln -s /usr/local/rrdtool/bin/rrdtool /usr/local/bin/rrdtool
